package miniappopen

import (
	"net/url"
	"sync"

	"github.com/bububa/opentaobao/model"
)

// TaobaoMiniappDistributionItemsBindAPIRequest 【已废弃】小程序投放-商品绑定/解绑 API请求
// taobao.miniapp.distribution.items.bind
//
// 【已废弃，请使用 taobao.miniapp.distribution.order.items.bind 接口】提供给使用了投放插件的服务商，可以调用该API实现帮助商家更新已创建的投放单中的绑定商品信息。
type TaobaoMiniappDistributionItemsBindAPIRequest struct {
	model.Params
	// 商品id列表
	_targetEntityList []string
	// 投放的商家应用完整链接
	_url string
	// true表示新增绑定，false表示解绑
	_addBind bool
}

// NewTaobaoMiniappDistributionItemsBindRequest 初始化TaobaoMiniappDistributionItemsBindAPIRequest对象
func NewTaobaoMiniappDistributionItemsBindRequest() *TaobaoMiniappDistributionItemsBindAPIRequest {
	return &TaobaoMiniappDistributionItemsBindAPIRequest{
		Params: model.NewParams(3),
	}
}

// Reset IRequest interface 方法, 清空结构体
func (r *TaobaoMiniappDistributionItemsBindAPIRequest) Reset() {
	r._targetEntityList = r._targetEntityList[:0]
	r._url = ""
	r._addBind = false
	r.Params.ToZero()
}

// GetApiMethodName IRequest interface 方法, 获取Api method
func (r TaobaoMiniappDistributionItemsBindAPIRequest) GetApiMethodName() string {
	return "taobao.miniapp.distribution.items.bind"
}

// GetApiParams IRequest interface 方法, 获取API参数
func (r TaobaoMiniappDistributionItemsBindAPIRequest) GetApiParams(params url.Values) {
	for k, v := range r.Params {
		params.Set(k, v.String())
	}
}

// GetRawParams IRequest interface 方法, 获取API原始参数
func (r TaobaoMiniappDistributionItemsBindAPIRequest) GetRawParams() model.Params {
	return r.Params
}

// SetTargetEntityList is TargetEntityList Setter
// 商品id列表
func (r *TaobaoMiniappDistributionItemsBindAPIRequest) SetTargetEntityList(_targetEntityList []string) error {
	r._targetEntityList = _targetEntityList
	r.Set("target_entity_list", _targetEntityList)
	return nil
}

// GetTargetEntityList TargetEntityList Getter
func (r TaobaoMiniappDistributionItemsBindAPIRequest) GetTargetEntityList() []string {
	return r._targetEntityList
}

// SetUrl is Url Setter
// 投放的商家应用完整链接
func (r *TaobaoMiniappDistributionItemsBindAPIRequest) SetUrl(_url string) error {
	r._url = _url
	r.Set("url", _url)
	return nil
}

// GetUrl Url Getter
func (r TaobaoMiniappDistributionItemsBindAPIRequest) GetUrl() string {
	return r._url
}

// SetAddBind is AddBind Setter
// true表示新增绑定，false表示解绑
func (r *TaobaoMiniappDistributionItemsBindAPIRequest) SetAddBind(_addBind bool) error {
	r._addBind = _addBind
	r.Set("add_bind", _addBind)
	return nil
}

// GetAddBind AddBind Getter
func (r TaobaoMiniappDistributionItemsBindAPIRequest) GetAddBind() bool {
	return r._addBind
}

var poolTaobaoMiniappDistributionItemsBindAPIRequest = sync.Pool{
	New: func() any {
		return NewTaobaoMiniappDistributionItemsBindRequest()
	},
}

// GetTaobaoMiniappDistributionItemsBindRequest 从 sync.Pool 获取 TaobaoMiniappDistributionItemsBindAPIRequest
func GetTaobaoMiniappDistributionItemsBindAPIRequest() *TaobaoMiniappDistributionItemsBindAPIRequest {
	return poolTaobaoMiniappDistributionItemsBindAPIRequest.Get().(*TaobaoMiniappDistributionItemsBindAPIRequest)
}

// ReleaseTaobaoMiniappDistributionItemsBindAPIRequest 将 TaobaoMiniappDistributionItemsBindAPIRequest 放入 sync.Pool
func ReleaseTaobaoMiniappDistributionItemsBindAPIRequest(v *TaobaoMiniappDistributionItemsBindAPIRequest) {
	v.Reset()
	poolTaobaoMiniappDistributionItemsBindAPIRequest.Put(v)
}
